#define BAUD 115200UL

#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/setbaud.h>
#include "vt100.h"
#include "t6963c.h"

ISR(USART0_RX_vect)
{
	char c;

	c = UDR0;
	if (bit_is_clear(UCSR0A, FE))
		VT100WriteCh(c);
}

static void setbaud(void)
{
	UBRR0H = UBRRH_VALUE;
	UBRR0L = UBRRL_VALUE;
	#if USE_2X
	UCSR0A |= (1 << U2X);
	#else
	UCSR0A &= ~(1 << U2X);
	#endif
}

int main(void)
{
	GLCD_Initalize(); // Initalize LCD
	GLCD_ClearText(); // Clear text area
	GLCD_ClearCG(); // Clear character generator area
	GLCD_ClearGraphic(); // Clear graphic area
	
	GLCD_TextGoTo(0,0);
	
	InitVT100();
	
	//Initialize UART
	UCSR0A = 0;
	UCSR0B = 0;
	UCSR0C = 6;
	setbaud();
	
	UCSR0B = _BV(RXEN) | _BV(RXCIE); /* tx/rx enable, rx complete intr */
	
	while(1)
	{
		sei();
		//set_sleep_mode(SLEEP_MODE_PWR_SAVE);
		//sleep_mode();
	}
	return 0;
}
